package com.yanqu.road.server.manager.activity.langyabang;

import com.yanqu.road.entity.activity.ActivityInfo;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CrossLangYaBangActivityGroup {

    private final Object lock = new Object();

    private ActivityInfo activityInfo;

    private Map<Integer, LangYaBangActivity> activityMap = new ConcurrentHashMap<>();


    public CrossLangYaBangActivityGroup(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
        CrossLangYaBangConfigMgr.reloadConfig();

    }


    public Map<Integer, LangYaBangActivity> getActivityMap() {
        return activityMap;
    }

    public LangYaBangActivity getActivity(int groupId) {
        if (!activityMap.containsKey(groupId)) {
            synchronized (activityMap) {
                if (!activityMap.containsKey(groupId)) {
                    LangYaBangActivity activity = new LangYaBangActivity(activityInfo.getActivityId(), groupId);
                    activity.loadDbData();
                    activityMap.put(groupId, activity);
                    CrossLangYaBangConfigMgr.reloadConfig(activityInfo);
                }
            }
        }
        return activityMap.get(groupId);
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }
}
